package br.edu.unifei.mestrado.grafo;

import br.edu.unifei.mestrado.commons.graph.NodeWrapper;
import br.edu.unifei.mestrado.commons.graph.RelationshipWrapper;
import br.edu.unifei.mestrado.mem.graph.Graph;
import edu.uci.ics.jung.graph.UndirectedSparseGraph;
/**
 * Classe que converte um grafo de Graph para UndirectedSparseGraph.
 * @author roberto
 *
 */
public class GrafoMemView extends Graph {

	private UndirectedSparseGraph<NodeWrapper, RelationshipWrapper> grafo;

	public GrafoMemView(String dbFileName, Integer level) {
		super(level, dbFileName);
		grafo = new UndirectedSparseGraph<NodeWrapper, RelationshipWrapper>();
	}

	//Util: converte o grafo em memoria UndirectedSparseGraph<Node, Relationship> para UndirectedSparseGraph<nodeWrapper, relationshipWrapper>
	@Override
	public void readGraph() {
		super.readGraph();

		for (NodeWrapper node : getAllNodes()) {
			grafo.addVertex(node);
		}
		// pega as arestas e nós do banco e joga na memoria
		for (RelationshipWrapper rel : getAllEdges()) {
			// Adiciona a aresta, e esse médodo já adiciona os nós se não existir
			grafo.addEdge(rel, rel.getStartNode(), rel.getEndNode());
		}
	}

	public UndirectedSparseGraph<NodeWrapper, RelationshipWrapper> getGrafoToView() {
		return grafo;
	}
}
